package com.k8s.base.domain;

import com.fasterxml.jackson.annotation.JsonIgnore;
import org.hibernate.annotations.Cache;
import org.hibernate.annotations.CacheConcurrencyStrategy;
import javax.persistence.*;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
import java.io.Serializable;
import java.time.LocalDateTime;
import java.util.Objects;

/**
 * 生成文件的存储信息
 */
@Entity
@Table(name = "generate_file_storage")
@Cache(usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE)
public class GenerateFileStorage implements Serializable {

    private static final long serialVersionUID = 1L;

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Long id;

    /**
     * 文件KEY
     */
    @NotNull
    @Size(max = 50)
    @Column(name = "file_key", length = 50, nullable = false)
    private String fileKey;

    /**
     * 文件名
     */
    @Size(max = 500)
    @Column(name = "file_name", length = 500)
    private String fileName;

    /**
     * 下载地址
     */
    @Column(name = "down_load_url")
    private String downLoadUrl;

    /**
     * 进度状态 BASE_GENERATE_FILE_STORAGE_STATUS
     * NEW - 新建
     * DONE - 完成
     * ERROR - 生成失败
     */
    @NotNull
    @Size(max = 20)
    @Column(name = "status", length = 20, nullable = false)
    private String status;

    /**
     * 信息
     */
    @Size(max = 500)
    @Column(name = "message", length = 500)
    private String message;

    /**
     * 生成时间
     */
    @NotNull
    @Column(name = "generate_time", nullable = false)
    private LocalDateTime generateTime;

    /**
     * 产生源
     */
    @NotNull
    @Size(max = 200)
    @Column(name = "source", length = 200, nullable = false)
    private String source;

    /**
     * 产生源名
     */
    @Size(max = 200)
    @Column(name = "source_name", length = 200)
    private String sourceName;

    /**
     * 有效时间
     * 为空 永久有效
     * 单位：秒
     */
    @Column(name = "expire_time")
    private LocalDateTime expireTime;

    /**
     * 产生源参数
     */
    @Column(name = "source_param")
    private String sourceParam;

    @ManyToOne(fetch = FetchType.LAZY)
    @JsonIgnore
    private GenerateFileStorageSetting setting;

    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public String getFileKey() {
        return fileKey;
    }

    public GenerateFileStorage fileKey(String fileKey) {
        this.fileKey = fileKey;
        return this;
    }

    public void setFileKey(String fileKey) {
        this.fileKey = fileKey;
    }

    public String getDownLoadUrl() {
        return downLoadUrl;
    }

    public GenerateFileStorage downLoadUrl(String downLoadUrl) {
        this.downLoadUrl = downLoadUrl;
        return this;
    }

    public void setDownLoadUrl(String downLoadUrl) {
        this.downLoadUrl = downLoadUrl;
    }

    public LocalDateTime getGenerateTime() {
        return generateTime;
    }

    public GenerateFileStorage generateTime(LocalDateTime generateTime) {
        this.generateTime = generateTime;
        return this;
    }

    public void setGenerateTime(LocalDateTime generateTime) {
        this.generateTime = generateTime;
    }

    public String getSource() {
        return source;
    }

    public GenerateFileStorage source(String source) {
        this.source = source;
        return this;
    }

    public void setSource(String source) {
        this.source = source;
    }

    public String getSourceParam() {
        return sourceParam;
    }

    public GenerateFileStorage sourceParam(String sourceParam) {
        this.sourceParam = sourceParam;
        return this;
    }

    public void setSourceParam(String sourceParam) {
        this.sourceParam = sourceParam;
    }

    public String getFileName() {
        return fileName;
    }

    public void setFileName(String fileName) {
        this.fileName = fileName;
    }

    public GenerateFileStorage fileName(String fileName) {
        this.fileName = fileName;
        return this;
    }

    public String getSourceName() {
        return sourceName;
    }

    public void setSourceName(String sourceName) {
        this.sourceName = sourceName;
    }

    public GenerateFileStorage sourceName(String sourceName) {
        this.sourceName = sourceName;
        return this;
    }

    public String getStatus() {
        return status;
    }

    public void setStatus(String status) {
        this.status = status;
    }

    public GenerateFileStorage status(String status) {
        this.status = status;
        return this;
    }

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    public GenerateFileStorage message(String message) {
        this.message = message;
        return this;
    }

    public LocalDateTime getExpireTime() {
        return expireTime;
    }

    public void setExpireTime(LocalDateTime expireTime) {
        this.expireTime = expireTime;
    }

    public GenerateFileStorage expireTime(LocalDateTime expireTime) {
        this.expireTime = expireTime;
        return this;
    }

    public GenerateFileStorageSetting getSetting() {
        return setting;
    }

    public void setSetting(GenerateFileStorageSetting setting) {
        this.setting = setting;
    }

    public GenerateFileStorage setting(GenerateFileStorageSetting setting) {
        this.setting = setting;
        return this;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) {
            return true;
        }
        if (o == null || getClass() != o.getClass()) {
            return false;
        }
        GenerateFileStorage generateFileStorage = (GenerateFileStorage) o;
        if (generateFileStorage.id == null || id == null) {
            return false;
        }
        return Objects.equals(id, generateFileStorage.id);
    }

    @Override
    public int hashCode() {
        return Objects.hashCode(id);
    }

    @Override
    public String toString() {
        return "GenerateFileStorage{" +
            "id=" + id +
            ", fileKey='" + fileKey + "'" +
            ", downLoadUrl='" + downLoadUrl + "'" +
            ", generateTime='" + generateTime + "'" +
            ", source='" + source + "'" +
            ", sourceParam='" + sourceParam + "'" +
            '}';
    }
}
